for (election2use in elections2use <- c("2012-GE", "2014-GE", "2016-GE", "2018-GE")) {
  
  start_date = election_dates[[election2use]] + as.difftime(-31, unit = "days")
  end_date = election_dates[[election2use]] + as.difftime(0, unit = "days")
  
  seq2use <- data.frame(seq(from = start_date, to = end_date, by = 1))
  names(seq2use) <- "received_date"
  
  abl2use <- abl_files[[election2use]] %>%
    filter(received_type == "MA",
           enrollment %in% c("D", "R", "U"),
           !is.na(received_date),
           received_date <= end_date,
           received_date >= start_date) %>%
    count(received_date, enrollment) %>%
    spread(enrollment, n) %>%
    left_join(x = seq2use, y = .) %>%
    replace(is.na(.), 0) %>%
    gather(key = "party", value = "count", D, R, U) %>%
    mutate(party = case_when(
      party == "D" ~ "Democratic",
      party == "R" ~ "Republican",
      party == "U" ~ "Unaffiliated")) %>%
    rename(`VBM ballots` = count)

  abl2use$year <- gsub("-", " ", election2use)
  abl2use$days_before <- seq(from = 31, to = 0, by = -1)
  
  if (match(election2use, elections2use) == 1) {
    results <- abl2use
  }
  else {
    results <- rbind(results, abl2use)
  }
}

p <- results %>%
  ggplot(aes(y = `VBM ballots` / 1000, x = -days_before,  shape = wday(received_date) %in% c(1,7))) +
  scale_shape_manual(guide = FALSE, values = c(21, 19)) +
  geom_point() +
  geom_smooth(se = FALSE, color = "gray") +
  scale_y_continuous(limits = c(0, 3.5)) + 
  ylab("Received VBM ballots (in thousands)") +
  xlab("Days before election") +
  facet_grid(year ~ party)
  
filename2use <- paste("~/research/vbm-vulnerable-maine/plots/maine-d-only-", election2use, ".pdf", sep = "")
ggsave(p, filename = "~/research/vbm-vulnerable-maine/plots/maine-d-u-r-by-year.pdf", width = 6, height = 6)
  
 